<?php

/**
 * This is the model class for table "njtab".
 */
class Njtab extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'njtab':
	 * @var integer $id
	 * @var string $name
	 * @var integer $price
	 * @var string $city
	 * @var string $company
	 * @var string $info
	 * @var string $image
	 * @var string $href
	 * @var string $num
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return Njtab the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'njtab';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('price', 'numerical', 'integerOnly'=>true),
			array('name, company, num', 'length', 'max'=>80),
			array('city', 'length', 'max'=>40),
			array('info, image, href', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, price, city, company, info, image, href, num', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name' => '产品',
			'price' => '价格',
			'city' => '产地',
			'company' => '公司',
			'info' => '简介',
			'image' => '图片',
			'href' => '链接',
			'num' => '型号',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.
		$data=explode('~',$this->price);
		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);

		$criteria->compare('name',$this->name,true);

		$criteria->compare('price','>='.$data[0]);
		if(count($data)!=1)
		$criteria->compare('price','<='.$data[1]);
		$criteria->compare('city',$this->city,true);

		$criteria->compare('company',$this->company,true);

		$criteria->compare('info',$this->info,true);

		$criteria->compare('image',$this->image,true);

		$criteria->compare('href',$this->href,true);

		$criteria->compare('num',$this->num,true);
		$criteria->order='price ASC';
		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
			));
	}
	
	public function search1()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.
		$data=explode('~',$this->price);
		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);

		$criteria->compare('name',$this->name,true);

		$criteria->compare('price','>='.$data[0]);
		if(count($data)!=1)
		$criteria->compare('price','<='.$data[1]);
		$criteria->compare('city',$this->city,true);

		$criteria->compare('company',$this->company,true);

		$criteria->compare('info',$this->info,true);

		$criteria->compare('image',$this->image,true);

		$criteria->compare('href',$this->href,true);

		$criteria->compare('num',$this->num,true);
		$criteria->order='price ASC';
		return $criteria;
	}
}